<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"   v-show="showSearch" label-width="68px">
      <el-form-item label="版本号" prop="versionNo">
        <el-input v-model.trim="queryParams.versionNo"   placeholder="请输入版本号" clearable
          @keyup.enter.native="handleQuery" />
          
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" size="small"   @click="handleQuery">搜索</el-button>
      <el-button
      type="primary"
      plain
      size="small"
      icon="el-icon-plus"
      @click="handleAdd"
      v-hasPermi="['projectManage:templete:add']"
    >添加模板</el-button>
    </el-form>
    
     
    <el-table border v-loading="loading" :data="projectList" ref="projectTable">
       
      <el-table-column label="版本号" align="center" prop="versionNo"></el-table-column>
      <el-table-column label="是否当前版本" align="center" prop="status" >
          <template slot-scope="scope">
            <dict-tag :options="dict.type.project_y_n" :value="scope.row.status"/>
          </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="nickName" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text"  
            icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['projectManage:templete:update']">修改</el-button>
          <!-- <el-button size="mini" type="text"  
            icon="el-icon-document-copy" @click="handleCopy(scope.row)" 
            v-hasPermi="['projectManage:templete:add']">复制</el-button> -->
          <el-button size="mini" type="text"  
            icon="el-icon-s-fold" @click="handleStatusChange(scope.row)" v-show="scope.row.status==1"
            v-hasPermi="['projectManage:templete:set']">设为当前版本</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 新增/修改弹窗 -->
    <project-templete ref="projectTemplete" @query="getList"  :title="title"></project-templete>

    
  </div>
</template>

<script>
import projectTemplete from "@/components/projectManage/templete/templete";
import {prepareAdd,getProjectTempleteList,updateStatus,copyTemplete}  from "@/api/projectManage/templete";

export default {
  name: "Project",
  components: { projectTemplete },
  dicts: ['project_status','project_y_n'],
  data() {
    return {
      update: false,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      //预添加模板ID
      prepareId:null,
      // 总条数
      total: 0,
      // 打样表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        versionNo:null
      },
    };
  },
  created() {
    this.getList()
  },
  methods: {

 
 
 
 
    /** 查询项目列表 */
    getList() {
      this.loading = true;
      getProjectTempleteList(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    //复制项目
    handleCopy(obj){
      this.$modal.loading("请稍候...");
      copyTemplete(obj).then(response => {
        this.$modal.closeLoading();
         
        this.prepareId = response.data;
        
        this.$refs.projectTemplete.open();  
        this.$refs.projectTemplete.init('新增项目模板',this.prepareId,false);
      });
    },
 
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
     
    /** 新增按钮操作 */
    handleAdd() {
      this.$modal.loading("请稍候...");
       
      prepareAdd({}).then(response => {
        this.$modal.closeLoading();
        this.prepareId = response.data;
        this.$refs.projectTemplete.open();  
        this.$refs.projectTemplete.init('新增项目模板',this.prepareId,false);
      });
      
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.projectTemplete.open();  
      this.$refs.projectTemplete.init('修改模板数据',row.id,true);
    },
 
 

    //设置成当前模板
    handleStatusChange(row) {
       
      this.$modal.confirm('是否确认版本号"' + row.versionNo + ' 设置成当前版本吗？"？').then(function () {
        return updateStatus(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => { });
    }, 
  }
};
</script>
 
